package com.example.interview.no0202.solution;

import com.example.interview.no0202.ListNode;
import com.example.interview.no0202.Solution;

/**
 * @Description 解答接口-返回倒数第 k 个节点
 * @ClassName SolutionImpl
 * @Author Administrator
 * @Date 2020/7/9 14:43
 * @Version 1.0.0
 */
public class SolutionImpl1 implements Solution {
    @Override
    public int kthToLast(ListNode head, int k) {
        ListNode p = head;
        for(int i=0; i<k; i++){
            p = p.next;
        }

        while(p != null){
            p = p.next;
            head = head.next;
        }

        return head.val;
    }
}
